﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.IO;
using System.Transactions;

namespace APH.Parl2.Client.Search.ASPNET.Pages
{
    public partial class Publish : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //PopulateTable();
        }

        public void PopulateControls()
        {
           

        }


        public void PopulateTable()
        {
            int i = 0;

            XmlDocument doc = new XmlDocument();

            doc.Load("C://ContentType.xml");

            foreach (XmlNode field in doc.DocumentElement.ChildNodes)
            {

                bool found = false;


                TextBox txtBox = new TextBox();
                txtBox.ID = "TxtID" + i + field.Name;

                Label lbl = new Label();
                lbl.ID = "LblID" + i + field.Name;
                lbl.Text = field.Name;
                
                TableRow row = new TableRow();
                TableCell cellLabel = new TableCell();
                cellLabel.Controls.Add(lbl);
                TableCell cellTxtBox = new TableCell();
                cellTxtBox.Controls.Add(txtBox);
                row.Cells.Add(cellLabel);
                row.Cells.Add(cellTxtBox);
                this.tblMetadata.Rows.Add(row);
                this.tblMetadata.Rows.Add(new TableRow());
            }


        }


        protected void cmdPublish_Click(object sender, EventArgs e)
        {
            var publishService = new PublishingManagerService.PublishingManagerClient();
            //publishService.UseDefaultCredentials = true;

            PublishingManagerService.IncomingDocumentData incomingData = new PublishingManagerService.IncomingDocumentData();
            incomingData.ContentType = "Document";
            incomingData.DocumentBytes = fileUpload.FileBytes;


            using (var ts = new TransactionScope())
            {
                publishService.Publish(incomingData);
                ts.Complete();
            }


           
        }


    }
}